// 遍历所有拐点生成解析式
function getAllAnalytical() {
	temp2 = inflectionPoint.concat();
	for(let i = 0; i < inflectionPoint.length; i++) {
		var pp = inflectionPoint[i];
		for(let i = 0; i < pp.nearPoint.length; i++) {
			analyticals.push(getAnalytical(pp, inflectionPoint[pp.nearPoint[i] - 1]));
		}
	}
	analyticals = AnalyticalsMoveRepeat(analyticals)
}

// 解析式去重
function AnalyticalsMoveRepeat(analyticals) {
	for(var i = 0; i < analyticals.length; i++) {
		for(var j = 1; j < analyticals.length - 1; j++) {
			if(i < analyticals.length) {
				if(checkAnalytical(analyticals[i], analyticals[j])) {
					analyticals.splice(j, 1);
				}
			}
		}
	}
	return analyticals;
}

// 判断解析式是否相等
function checkAnalytical(a1, a2) {
	var k1 = a1.k,
		k2 = a2.k,
		b1 = a1.b,
		b2 = a2.b,
		d1 = a1.d,
		d2 = a2.d;
	var x11 = a1.p1.x,
		x12 = a1.p2.x,
		x21 = a2.p1.x,
		x22 = a2.p2.x;
	var y11 = a1.p1.y,
		y12 = a1.p2.y,
		y21 = a2.p1.y,
		y22 = a2.p2.y;
	if(k1 == k2 && b1 == b2 && d1 == d2) {
		if(x11 == x22 && x12 == x21 && y11 == y22 && y12 == y21) {
			return true;
		}
	}
	return false;
}

// 计算任意两个点的解析式
function getAnalytical(a, b) {
	var x1 = a.x,
		x2 = b.x,
		y1 = a.y,
		y2 = b.y,
		k, b, d;
	if(x1 != x2) {
		k = (y1 - y2) / (x1 - x2);
		k = k.toFixed(2) * 1;
		b = (x1 * y2 - x2 * y1) / (x1 - x2);
		b = b.toFixed(2) * 1;
	} else {
		k = null;
		b = null;
	}
	d = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
	d = d.toFixed(2) * 1;
	var p1 = Point.createNew(x1, y1);
	var p2 = Point.createNew(x2, y2);
	var analytical = Analytical.createNew(p1, p2, k, b, d);
	return analytical;
}